package com.kangfawei.io;

import java.io.*;

/**
 * @author 康发伟
 * 打印流测试
 */
public class PrintStreamTest {
    public static void main(String[] args) {
        PrintStream ps = System.out;
        ps.println("今天是个好日子");
        ps.println(110);

        try {
            ps = new PrintStream("E:/IO_target/printStream.txt");
            ps.println("测试写入文件");

            ps = new PrintStream(new BufferedOutputStream(new FileOutputStream("E:/IO_target/printStream2.txt")),true);
            ps.println("测试写入文件2");

            // 重定向输出端
            System.setOut(ps);
            System.out.println("重定向输出端之后！");

            // 重定向回到控制台
            System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
            System.out.println("我回来了");

            ps.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }



    }
}
